package com.dhl.springbootrabbitmq.listening;

import com.dhl.springbootrabbitmq.config.DelayedTtlQueueConfig;
import com.dhl.springbootrabbitmq.config.TtlQueueConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * rabbit监听器,监听延迟队列
 * @author danghailiang
 */
@Slf4j
@Component
public class RabbitDelayedListening {
    /**
     * 监听对列
     * @param message
     * @param channel
     */
    @RabbitListener( queues = DelayedTtlQueueConfig.DELAYED_QUEUE)
    public void receiveD(Message message, Channel channel){
        log.info("时间是：{}，数据是：{},将要转发给队列！！！！",new Date(), new String(message.getBody(),StandardCharsets.UTF_8));
    }
}
